package com.backend.conmon.response;

public class CommonResponse2<T> implements ICommonResponse2<T> {

  private String code;

  private String msg;

  private T datas;

  /**
   *
   */
  public CommonResponse2() {
    this(null, null, null);
  }

  public CommonResponse2(String code, String msg) {
    this(code, msg, null);
  }

  public CommonResponse2(String code, String msg, T datas) {
    this.code = code;
    this.msg = msg;
    this.datas = datas;
  }

  public static <T> CommonResponse2<T> error(String msg) {
    return new CommonResponse2<>(FAIL_CODE, msg, null);
  }

  public static <T> CommonResponse2<T> error(String code, String msg) {
    return new CommonResponse2<>(code, msg, null);
  }

  public static <T> CommonResponse2<T> error() {
    return error("未知错误");
  }

  @Override
  public String getMsg() {
    return msg;
  }

  @Override
  public void setMsg(String msg) {
    this.msg = msg;
  }

  @Override
  public String getCode() {
    return code;
  }

  @Override
  public void setCode(String code) {
    this.code = code;
  }

  /**
   * @return the datas
   */
  @Override
  public T getDatas() {
    return datas;
  }

  /**
   * @param datas the datas to set
   */
  @Override
  public void setDatas(T datas) {
    this.datas = datas;
  }


  public static CommonResponse2<Void> success(){
    return success(null);
  }

  public static <T> CommonResponse2 success(T datas){
    CommonResponse2<T> commonResponse2 = new CommonResponse2<>();
    commonResponse2.setCode(SUCCESS_CODE);
    commonResponse2.setMsg(SUCCESS_MSG);
    commonResponse2.setDatas(datas);
    return commonResponse2;
  }



}
